package com.example.myblog.dao;

import com.example.myblog.pojo.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @BelongsProject: MyBlog
 * @BelongsPackage: com.example.myblog.dao
 * @ClassName CommentDao
 * @CreateTime: 2025-06-10  09:37
 * @Author: TangLiFei
 */
@Mapper
public interface CommentDao {
    //查询所有评论
    @Select("SELECT id,article_id,created,content,author FROM t_comment ORDER BY created DESC")
    List<Comment> findAll();

    // 发表评论
    @Insert("INSERT INTO t_comment (article_id,created,author,ip,content)" +
            " VALUES (#{articleId}, #{created},#{author},#{ip},#{content})")
    public void pushComment(Comment comment);

    // 站点服务统计，统计评论数量
    @Select("SELECT COUNT(1) FROM t_comment")
    public Integer countComment();

    // 修改评论
    @Update("update t_comment set content=#{content},author=#{author} where id=#{id}")
    public void update(Comment article);

    // 通过文章id删除评论信息
    @Delete("DELETE FROM t_comment WHERE article_id=#{aid}")
    public void deleteCommentWithId(Integer aid);

    // 根据评论ID删除评论
    @Delete("DELETE FROM t_comment WHERE id=#{id}")
    public void deleteCommentById(Integer id);

    // 分页展示某个文章的评论
    @Select("SELECT * FROM t_comment WHERE article_id=#{aid} ORDER BY id DESC")
    public List<Comment> selectCommentWithPage(Integer aid);
}
